
import javax.microedition.lcdui.*;

import javax.microedition.lcdui.game.Sprite;
public class b extends Canvas {


    private Display display;
    


    String[] label = {"Chat","Album", "Blog", "Friend", "Upload", "Profile", "Shoping", "Game", "Media"};
    int selectedIndex;
    private String title = new String("MAIN MENU");


    Image image1, image2, image3, image4, image5, image6;
    int top = 31;
    int x = 9;
    int a = 3;
    int b = 3;
    int width = (this.getWidth()-x*2)/a;
    int height = (this.getHeight()-x)/b;
    private String command = new String(" ");
    public b(){
        setFullScreenMode(true);

        try {
            image1 = Image.createImage("/ictop.png");
            image2 = Image.createImage("/icitem.png");
            image3 = Image.createImage("/icwall.png");
            image4 = Image.createImage("/icbottom.png");
            image5 = Image.createImage("/icitem2.png");
            image6 = Image.createImage("/icitem3.png");
        } catch (Exception ex){System.out.println("Error to load image!");}


    }
    protected void paint(Graphics g) {
        g.setColor(0xe9fcd2);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        g.setFont(f);
        g.setColor(0xccff33);
        
        g.fillRect(x+(selectedIndex%3)*width, (top+x+a)+(selectedIndex/3)*height, width, height);
        g.setColor(0x000000);
        g.drawImage(image1, 0, 0, Graphics.TOP | Graphics.LEFT);
        
        g.drawImage(image3, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);
        g.drawImage(image4, getWidth(), getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
        


        for (int i=0; i<label.length;i++){

            g.drawRegion(image2, 0, 0, 55,55, Sprite.TRANS_NONE, x+(i%a)*width+width/2, top+(i/9)*height+width/2, Graphics.VCENTER | Graphics.HCENTER);
            g.drawRegion(image5, 0, 0, 55,55, Sprite.TRANS_NONE, x+(i%a)*width+width/2, top+(i/6)*height+width/2, Graphics.VCENTER | Graphics.HCENTER);
            g.drawRegion(image6, 0, 0, 55,55, Sprite.TRANS_NONE, x+(i%a)*width+width/2, top+(i/3)*height+width/2, Graphics.VCENTER | Graphics.HCENTER);


            g.drawString(label[i], x+(i%3)*width+width/2, top+(i/3)*height+width, Graphics.TOP | Graphics.HCENTER);
        }
        g.setColor(0xccff11);
        Font f2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        g.setFont(f2);
        g.drawString(title, getWidth()/2, a + b, Graphics.TOP | Graphics.HCENTER);
        Font f3 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        g.setFont(f3);
        g.setColor(0xffffff);
        g.drawString(command, getWidth()/2, getHeight()-2, Graphics.BOTTOM | Graphics.LEFT);

    }

   protected void keyPressed(int keyCode)

  {





       int gameAction = getGameAction(keyCode);
        switch (gameAction){
        case RIGHT:

            selectedIndex = (byte) (++selectedIndex%label.length);
            repaint();
        }
        switch (gameAction){
        case LEFT:
            selectedIndex = (--selectedIndex)%label.length;
            if (selectedIndex==-1) selectedIndex = label.length-1;
            repaint();
        }
        switch (gameAction){
        case UP:
            selectedIndex -= a;
            if (selectedIndex<0) selectedIndex = ((label.length-1)/3)*a+(selectedIndex+a);
            if (selectedIndex >= label.length) selectedIndex = label.length-1;
            repaint();
        }
        switch (gameAction){
        case DOWN:
            selectedIndex += a;
            if (selectedIndex>=label.length)
                if (selectedIndex/3 == (label.length-1)/3) selectedIndex = label.length-1;
                else selectedIndex = selectedIndex%3;
            repaint();
        }






   }









}